﻿/********************************************************************************
    Copyright (C) Binod Nepal, Planet Earth Solutions Pvt. Ltd., Kathmandu.
	Released under the terms of the GNU General Public License, GPL, 
	as published by the Free Software Foundation, either version 3 
	of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MixNP.Web.Classifieds.Account.Confirmation
{
    public partial class ConfirmRegistration : MixNP.BusinessLayer.BaseClass
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string thanks = "<h2>Hey, we are proud to have a cool member here<em>!!!</em></h2><h2>So why don't you <a href=\"/sign-in.mix\">sign in</a> now?</h2>";
            string invalidToken = "<h2>Hey, that was not a valid token. We have now logged your IP.</h2>";
            string alreadyRegistered = "<h2>Hey, you have already confirmed.<em>!!!</em></h2><h2>So why don't you <a href=\"/sign-in.mix\">sign in</a> now?</h2>";
            string salt = string.Empty;

            if (RouteData.Values["salt"] != null)
            {
                salt = RouteData.Values["salt"].ToString();            
            }

            if (MixNP.BusinessLayer.Users.IsValidToken(salt))
            {
                if (MixNP.BusinessLayer.Users.IsTokenConfirmed(salt))
                {
                    Literal1.Text = alreadyRegistered;
                }
                else
                {
                    MixNP.BusinessLayer.Users.ConfirmRegistration(salt);
                    Literal1.Text = thanks;
                }
            }
            else
            {
                Literal1.Text = invalidToken;
                Pes.Utility.PageUtility.InvalidPasswordAttempts(this.Page, 1);
            }

        }


    }
}